package com.qingke.easyjava.springhibernate.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qingke.easyjava.springhibernate.bean.Category;
import com.qingke.easyjava.springhibernate.bean.Expense;
import com.qingke.easyjava.springhibernate.bean.User;

@Service
@Transactional
public class ExpenseService {

    @Autowired
    private HibernateManager hibernateManager;

    public void saveExpense(Expense expense) {
        hibernateManager.save(expense);
    }

    public List<Expense> listExpense() {
        return hibernateManager.getAllList(Expense.class);
    }

    public Category getCategoryByCode(String code) {
        return hibernateManager.getObjectByCode(Category.class, code);
    }
    
    public boolean isUserExists(String username,String password){
    	return hibernateManager.isUserExists(username, password);
    }
    
    public boolean isUsernameExists(String username){
    	return hibernateManager.isObjectExists(User.class, username);
    }
    
    public void insertUser(User user){
    	hibernateManager.save(user);
    }
    

}
